﻿using System;
using System.ComponentModel;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;
using LiveCharts.Definitions.Points;
using LiveCharts.Wpf;
using LiveCharts.Wpf.Points;

namespace LiveCharts.Wpf
{
    public class GLineSeries : LineSeries
    {
        public GLineSeries()
        {
        }

        public GLineSeries(object configuration) : base(configuration)
        {
        }

        public override IChartPointView GetPointView(ChartPoint point, string label)
        {
            //return this.method_0(point.View, point, label);
            HorizontalBezierPointView horizontalBezierPointView = (HorizontalBezierPointView)point.View;
            if (horizontalBezierPointView == null)
            {
                horizontalBezierPointView = new HorizontalBezierPointView
                {
                    Segment = new BezierSegment(),
                    Container = base.Figure,
                    IsNew = true
                };
            }
            else
            {
                horizontalBezierPointView.IsNew = false;
                point.SeriesView.Model.Chart.View.EnsureElementBelongsToCurrentDrawMargin(horizontalBezierPointView.Shape);
                point.SeriesView.Model.Chart.View.EnsureElementBelongsToCurrentDrawMargin(horizontalBezierPointView.DataLabel);
            }
            if (base.PointGeometry != null && Math.Abs(base.PointGeometrySize) > 0.1 && horizontalBezierPointView.Shape == null)
            {
                if (base.PointGeometry != null)
                {
                    horizontalBezierPointView.Shape = new Path
                    {
                        Stretch = Stretch.Fill,
                        ClipToBounds = true,
                        StrokeThickness = base.StrokeThickness
                    };
                }
                base.Model.Chart.View.AddToDrawMargin(horizontalBezierPointView.Shape);
            }
            if (horizontalBezierPointView.Shape != null)
            {
                horizontalBezierPointView.Shape.Fill = base.PointForeground;
                horizontalBezierPointView.Shape.Stroke = base.Stroke;
                horizontalBezierPointView.Shape.StrokeThickness = base.StrokeThickness;
                horizontalBezierPointView.Shape.Width = base.PointGeometrySize;
                horizontalBezierPointView.Shape.Height = base.PointGeometrySize;
                horizontalBezierPointView.Shape.Data = base.PointGeometry;
                horizontalBezierPointView.Shape.Visibility = base.Visibility;
                Panel.SetZIndex(horizontalBezierPointView.Shape, Panel.GetZIndex(this) + 1);
                if (point.Stroke != null)
                {
                    horizontalBezierPointView.Shape.Stroke = (Brush)point.Stroke;
                }
                if (point.Fill != null)
                {
                    horizontalBezierPointView.Shape.Fill = (Brush)point.Fill;
                }
            }
            if (base.DataLabels && horizontalBezierPointView.DataLabel == null)
            {
                horizontalBezierPointView.DataLabel = (horizontalBezierPointView.DataLabel = base.UpdateLabelContent(new DataLabelViewModel
                {
                    FormattedText = label,
                    Point = point
                }, horizontalBezierPointView.DataLabel));
            }
            if (!base.DataLabels && horizontalBezierPointView.DataLabel != null)
            {
                base.Model.Chart.View.RemoveFromDrawMargin(horizontalBezierPointView.DataLabel);
                horizontalBezierPointView.DataLabel = null;
            }
            return horizontalBezierPointView;
        }

        private IChartPointView method_0(IChartPointView ichartPointView_0, ChartPoint chartPoint_0, string string_0)
        {
            HorizontalBezierPointView horizontalBezierPointView = (HorizontalBezierPointView)ichartPointView_0;
            if (horizontalBezierPointView == null)
            {
                horizontalBezierPointView = new HorizontalBezierPointView
                {
                    Segment = new BezierSegment(),
                    Container = base.Figure,
                    IsNew = true
                };
            }
            else
            {
                horizontalBezierPointView.IsNew = false;
                chartPoint_0.SeriesView.Model.Chart.View.EnsureElementBelongsToCurrentDrawMargin(horizontalBezierPointView.Shape);
                chartPoint_0.SeriesView.Model.Chart.View.EnsureElementBelongsToCurrentDrawMargin(horizontalBezierPointView.DataLabel);
            }
            if (base.PointGeometry != null && Math.Abs(base.PointGeometrySize) > 0.1 && horizontalBezierPointView.Shape == null)
            {
                if (base.PointGeometry != null)
                {
                    horizontalBezierPointView.Shape = new Path
                    {
                        Stretch = Stretch.Fill,
                        ClipToBounds = true,
                        StrokeThickness = base.StrokeThickness
                    };
                }
                base.Model.Chart.View.AddToDrawMargin(horizontalBezierPointView.Shape);
            }
            if (horizontalBezierPointView.Shape != null)
            {
                horizontalBezierPointView.Shape.Fill = base.PointForeground;
                horizontalBezierPointView.Shape.Stroke = base.Stroke;
                horizontalBezierPointView.Shape.StrokeThickness = base.StrokeThickness;
                horizontalBezierPointView.Shape.Width = base.PointGeometrySize;
                horizontalBezierPointView.Shape.Height = base.PointGeometrySize;
                horizontalBezierPointView.Shape.Data = base.PointGeometry;
                horizontalBezierPointView.Shape.Visibility = base.Visibility;
                Panel.SetZIndex(horizontalBezierPointView.Shape, Panel.GetZIndex(this) + 1);
                if (chartPoint_0.Stroke != null)
                {
                    horizontalBezierPointView.Shape.Stroke = (Brush)chartPoint_0.Stroke;
                }
                if (chartPoint_0.Fill != null)
                {
                    horizontalBezierPointView.Shape.Fill = (Brush)chartPoint_0.Fill;
                }
            }
            if (base.DataLabels && horizontalBezierPointView.DataLabel == null)
            {
                horizontalBezierPointView.DataLabel = (horizontalBezierPointView.DataLabel = base.UpdateLabelContent(new DataLabelViewModel
                {
                    FormattedText = string_0,
                    Point = chartPoint_0
                }, horizontalBezierPointView.DataLabel));
            }
            if (!base.DataLabels && horizontalBezierPointView.DataLabel != null)
            {
                base.Model.Chart.View.RemoveFromDrawMargin(horizontalBezierPointView.DataLabel);
                horizontalBezierPointView.DataLabel = null;
            }
            return horizontalBezierPointView;
        }
    }
}
